﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
	/// <summary>
	/// 数据访问类ALARM_TRANSMIT。
	/// </summary>
	public class ALARM_TRANSMIT
	{
		public ALARM_TRANSMIT()
		{}
		#region  成员方法
        public int GetMaxID()
        {
            return OracleHelper.GetMaxID("alarmtransmitid", "alarm_transmit");
        }
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ALARMTRANSMITID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ALARM_TRANSMIT");
			strSql.Append(" where ALARMTRANSMITID=:ALARMTRANSMITID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ALARMTRANSMITID", OracleType.VarChar,50)};
			parameters[0].Value = ALARMTRANSMITID;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(FiberRMS.Model.AlarmManager.ALARM_TRANSMIT model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ALARM_TRANSMIT(");
			strSql.Append("ALARMTRANSMITID,STARTTIME,ENDTIME,TRANSMITMETHOD,ISUSE,ALARMTRANSNAME,ALARMMAPIDS,USERS)");
			strSql.Append(" values (");
			strSql.Append(":ALARMTRANSMITID,:STARTTIME,:ENDTIME,:TRANSMITMETHOD,:ISUSE,:ALARMTRANSNAME,:ALARMMAPIDS,:USERS)");
			OracleParameter[] parameters = {
					new OracleParameter(":ALARMTRANSMITID", OracleType.VarChar,10),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":TRANSMITMETHOD", OracleType.VarChar,20),
					new OracleParameter(":ISUSE", OracleType.VarChar,2),
					new OracleParameter(":ALARMTRANSNAME", OracleType.VarChar,100),
					new OracleParameter(":ALARMMAPIDS", OracleType.Clob),
					new OracleParameter(":USERS", OracleType.VarChar,2000)};
			parameters[0].Value = model.ALARMTRANSMITID;
			parameters[1].Value = model.STARTTIME;
			parameters[2].Value = model.ENDTIME;
			parameters[3].Value = model.TRANSMITMETHOD;
			parameters[4].Value = model.ISUSE;
			parameters[5].Value = model.ALARMTRANSNAME;
			parameters[6].Value = model.ALARMMAPIDS;
			parameters[7].Value = model.USERS;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(FiberRMS.Model.AlarmManager.ALARM_TRANSMIT model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ALARM_TRANSMIT set ");
			strSql.Append("STARTTIME=:STARTTIME,");
			strSql.Append("ENDTIME=:ENDTIME,");
			strSql.Append("TRANSMITMETHOD=:TRANSMITMETHOD,");
			strSql.Append("ISUSE=:ISUSE,");
			strSql.Append("ALARMTRANSNAME=:ALARMTRANSNAME,");
			strSql.Append("ALARMMAPIDS=:ALARMMAPIDS,");
			strSql.Append("USERS=:USERS");
			strSql.Append(" where ALARMTRANSMITID=:ALARMTRANSMITID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMTRANSMITID", OracleType.VarChar,10),
					new OracleParameter(":STARTTIME", OracleType.DateTime),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":TRANSMITMETHOD", OracleType.VarChar,20),
					new OracleParameter(":ISUSE", OracleType.VarChar,2),
					new OracleParameter(":ALARMTRANSNAME", OracleType.VarChar,100),
					new OracleParameter(":ALARMMAPIDS", OracleType.Clob),
					new OracleParameter(":USERS", OracleType.VarChar,2000)};
			parameters[0].Value = model.ALARMTRANSMITID;
			parameters[1].Value = model.STARTTIME;
			parameters[2].Value = model.ENDTIME;
			parameters[3].Value = model.TRANSMITMETHOD;
			parameters[4].Value = model.ISUSE;
			parameters[5].Value = model.ALARMTRANSNAME;
			parameters[6].Value = model.ALARMMAPIDS;
			parameters[7].Value = model.USERS;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string ALARMTRANSMITID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete ALARM_TRANSMIT ");
			strSql.Append(" where ALARMTRANSMITID=:ALARMTRANSMITID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ALARMTRANSMITID", OracleType.VarChar,50)};
			parameters[0].Value = ALARMTRANSMITID;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public FiberRMS.Model.AlarmManager.ALARM_TRANSMIT GetModel(string ALARMTRANSMITID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ALARMTRANSMITID,STARTTIME,ENDTIME,TRANSMITMETHOD,ISUSE,ALARMTRANSNAME,ALARMMAPIDS,USERS from ALARM_TRANSMIT ");
			strSql.Append(" where ALARMTRANSMITID=:ALARMTRANSMITID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ALARMTRANSMITID", OracleType.VarChar,50)};
			parameters[0].Value = ALARMTRANSMITID;

			FiberRMS.Model.AlarmManager.ALARM_TRANSMIT model=new FiberRMS.Model.AlarmManager.ALARM_TRANSMIT();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.ALARMTRANSMITID=ds.Tables[0].Rows[0]["ALARMTRANSMITID"].ToString();
				if(ds.Tables[0].Rows[0]["STARTTIME"].ToString()!="")
				{
					model.STARTTIME=DateTime.Parse(ds.Tables[0].Rows[0]["STARTTIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ENDTIME"].ToString()!="")
				{
					model.ENDTIME=DateTime.Parse(ds.Tables[0].Rows[0]["ENDTIME"].ToString());
				}
				model.TRANSMITMETHOD=ds.Tables[0].Rows[0]["TRANSMITMETHOD"].ToString();
				model.ISUSE=ds.Tables[0].Rows[0]["ISUSE"].ToString();
				model.ALARMTRANSNAME=ds.Tables[0].Rows[0]["ALARMTRANSNAME"].ToString();
				model.ALARMMAPIDS=ds.Tables[0].Rows[0]["ALARMMAPIDS"].ToString();
				model.USERS=ds.Tables[0].Rows[0]["USERS"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ALARMTRANSMITID,STARTTIME,ENDTIME,TRANSMITMETHOD,ISUSE,ALARMTRANSNAME,ALARMMAPIDS,USERS ");
			strSql.Append(" FROM ALARM_TRANSMIT ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
		}
        /// <summary>
        /// 获得子系统名称
        /// </summary>
        /// <param name="codeid"></param>
        /// <param name="codevalue"></param>
        /// <param name="table"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public DataSet getCommCode(string codeid, string codevalue, string table, string value)
        {
            string strSql = "";
            if (value != "")
            {
                strSql = "select  distinct " + codeid + "," + codevalue + " from " + table + " where " + codeid + " like '" + value + "__'";
            }
            else
            {
                strSql = "select distinct " + codeid + "," + codevalue + " from " + table;
            }
            return OracleHelper.Query(strSql);
        }
        public DataSet getCommCode_Order(string codeid, string codevalue, string table, string value, string order)
        {

            string strSql = "";
            if (value != "")
            {
                strSql = "select  distinct " + codeid + "," + codevalue + " from " + table + " where " + codeid + " like '" + value + "__'";
            }
            else
            {
                strSql = "select distinct " + codeid + "," + codevalue + " from " + table;
            }
            if (order != "")
            {
                strSql += " order by " + order + "";
            }
            return OracleHelper.Query(strSql);
        }

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "ALARM_TRANSMIT";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

